package com.blue.firecat.vo;

import com.blue.firecat.contants.Contants;
import com.blue.firecat.enums.OrderTypeEnum;
import com.blue.firecat.utils.CharUtil;
import com.blue.firecat.utils.date.DateUtil;
import org.apache.commons.lang3.StringUtils;

import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.Date;

/**
 * @描述
 * @时间 2017-6-23 17:13
 * @作者 肖亦鸣
 */
public class OrderVo {
    private Long orderId;
    private Long userId;
    private Integer gameId;
    private String gameName;
    private Integer orderType;
    private Integer orderTypeSelect;
    private String orderTypeString;
    private String datemin = LocalDate.now().minusMonths(1).toString() + " 00:00:00";
    private String datemax = LocalDate.now().plusMonths(1).toString() + " 00:00:00";

    private Date dateMin = DateUtil.getDateByString(LocalDate.now().minusMonths(1).toString() + " 00:00:00");
    private Date dateMax = DateUtil.getDateByString(LocalDate.now().plusMonths(1).toString() + " 00:00:00");

    private BigDecimal priceMin = BigDecimal.ZERO;
    private BigDecimal priceMax = new BigDecimal(2000);

    public String getDatemin() {
        return datemin;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public void setDatemin(String datemin) {
        this.datemin = datemin;
        if (StringUtils.isEmpty(datemin)) {
            this.setDateMin(DateUtil.getDateByString(Contants.DATE_MIN));
        } else {
            this.setDateMin(DateUtil.getDateByString(datemin));
        }
    }

    public String getDatemax() {
        return datemax;
    }

    public void setDatemax(String datemax) {
        this.datemax = datemax;
        if (StringUtils.isEmpty(datemax)) {
            this.setDateMax(DateUtil.getDateByString(Contants.DATE_MAX));
        } else {
            this.setDateMax(DateUtil.getDateByString(datemax));
        }
    }

    public BigDecimal getPriceMin() {
        return priceMin;
    }

    public void setPriceMin(BigDecimal priceMin) {
        this.priceMin = priceMin;
    }

    public BigDecimal getPriceMax() {
        return priceMax;
    }

    public void setPriceMax(BigDecimal priceMax) {
        this.priceMax = priceMax;
    }

    public String getGameName() {
        return gameName;
    }

    public void setGameName(String gameName) {
        this.gameName = gameName;
    }

    public Long getOrderId() {
        return orderId;
    }

    public void setOrderId(Long orderId) {
        this.orderId = orderId;
    }

    public Integer getGameId() {
        return gameId;
    }

    public void setGameId(Integer gameId) {
        if (gameId == -1) {
            return;
        }
        this.gameId = gameId;
        Contants.TRADE_GAME_RESULT.getData().stream().filter(game -> gameId.equals(game.getId())).forEach(game -> {
            this.setGameName(game.getName());
        });
    }

    public Integer getOrderType() {
        return orderType;
    }

    public void setOrderType(Integer orderType) {
        this.orderType = orderType;
    }

    public Integer getOrderTypeSelect() {
        return orderTypeSelect;
    }

    public void setOrderTypeSelect(Integer orderTypeSelect) {
        this.orderTypeSelect = orderTypeSelect;
    }

    public String getOrderTypeString() {
        return orderTypeString;
    }

    public void setOrderTypeString(String orderTypeString) {
        if (!CharUtil.isChinese(orderTypeString)) {
            try {
                orderTypeString = new String(orderTypeString.getBytes("ISO-8859-1"), "UTF-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
        this.setOrderType(OrderTypeEnum.getCodeByValue(orderTypeString));
        this.setOrderTypeSelect(OrderTypeEnum.getCodeByValue(orderTypeString));
        this.orderTypeString = orderTypeString;
    }

    public Date getDateMin() {
        if (dateMin == null) {
            this.setDateMin(DateUtil.getDateByString(Contants.DATE_MIN));
        }
        return dateMin;
    }

    public void setDateMin(Date dateMin) {
        this.dateMin = dateMin;
    }

    public Date getDateMax() {
        if (dateMin == null) {
            this.setDateMax(DateUtil.getDateByString(Contants.DATE_MAX));
        }
        return dateMax;
    }

    public void setDateMax(Date dateMax) {
        this.dateMax = dateMax;
    }
}

